package com.augurit.wf.app.document.utils;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;


public class FileUtil {
	
	private static Long BUFFER_SIZE = 1000 * 1024l ;

	
	public static void setBUFFER_SIZE(Long buffer_size) {
		BUFFER_SIZE = buffer_size;
	}


	public static Long getBUFFER_SIZE() {
		return BUFFER_SIZE;
	}


	public static void copy(File src, File dst)  {
        try  {
           InputStream in = null ;
           OutputStream out = null ;
            try  {                
                 in = new BufferedInputStream( new FileInputStream(src),BUFFER_SIZE.intValue());
                 out = new BufferedOutputStream( new FileOutputStream(dst), BUFFER_SIZE.intValue());
                byte [] buffer = new byte [BUFFER_SIZE.intValue()];
                while (in.read(buffer) > 0 )  {
                   out.write(buffer);
               } 
            } finally  {
                if ( null != in)  {
                   in.close();
               } 
                 if ( null != out)  {
                   out.close();
               } 
           } 
        } catch (Exception e)  {
           e.printStackTrace();
       } 
   } 
	
	public static String getType(String filename){
		int pos = filename.lastIndexOf( "." );
        return filename.substring(pos);
	}
	



}
